import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)  //核心插件

import { INC } from "../Name"
import shopping from "./shopping"
import car from "./car"
let state = {
  count: 1,
  eag: "薛世斌",
  arr: [
    {
      id: 1
    },
    {
      id: 2
    },
    {
      id: 3
    }
  ]
}


const mutations = { //
  [INC](state, obj) {
    // console.log(obj);

    state.count += obj.num
  },
  jian(state, obj) {
    state.count -= 1
  }
}

const actions = {
  fnn(context) {

    context.commit('inc', { num: 100 })
    // context.commit({type:"inc",num:88})
  },
  addfn({ commit, dispatch }, params) {
    dispatch('fnn')

    //   commit({
    //     type: "add",
    //     num: params.num
    //   })
  }
}

const getters = {
  con(state) {
    return state.count += 10
  }
  // arrLength(state) {
  //   // return  state.arr.length
  //   return (id) => state.arr.filter((value) => { //这是是函数在 表现层就可以调用这个函数了
  //       return value.id == id
  //     })

  // }


}
// export default store

// export {
//   store
// }

export default new Vuex.Store({
  actions,
  getters,
  state,
  mutations,
  modules: {
    shopping,
    car
  }
})
